/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * RemoveUsuario.java
 *
 * Created on 10/07/2009, 18:47:00
 */
package interfaceGraficaUsuario;

import controle.Sistema;
import java.awt.Color;
import users.Usuario;

/**
 *
 * @author João Paulo
 */
public class RemoveUsuario extends javax.swing.JFrame {
    private String loginProfessor;

    /** Creates new form RemoveUsuario */
    public RemoveUsuario() {
        initComponents();
        
    }

    /** Creates new form RemoveUsuario */
    public RemoveUsuario(String login) {
        initComponents();
        setTitle("Remover Usuário");
        this.loginProfessor = login;
        labelNotFound.setForeground(Color.RED);
        labelNotFound.setVisible(false);
        labelRemovido.setForeground(Color.BLUE);
        labelRemovido.setVisible(false);
        labelNaoRemovido.setForeground(Color.RED);
        labelNaoRemovido.setVisible(false);
        campoID.setText("0");
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        labelMatricula = new javax.swing.JLabel();
        labelNome = new javax.swing.JLabel();
        labelEmail = new javax.swing.JLabel();
        botaoRemover = new javax.swing.JButton();
        botaoCancelar = new javax.swing.JButton();
        campoEmail = new javax.swing.JTextField();
        campoNome = new javax.swing.JTextField();
        campoMatricula = new javax.swing.JTextField();
        labelID = new javax.swing.JLabel();
        campoID = new javax.swing.JTextField();
        botaoProcurarID = new javax.swing.JButton();
        labelNotFound = new javax.swing.JLabel();
        labelRemovido = new javax.swing.JLabel();
        labelNaoRemovido = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setMinimumSize(new java.awt.Dimension(550, 350));

        labelMatricula.setText("Matricula:");

        labelNome.setText("Nome:");

        labelEmail.setText("E-Mail:");

        botaoRemover.setText("Remover");
        botaoRemover.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                botaoRemoverMouseClicked(evt);
            }
        });
        botaoRemover.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoRemoverActionPerformed(evt);
            }
        });

        botaoCancelar.setText("Cancelar");
        botaoCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoCancelarActionPerformed(evt);
            }
        });

        labelID.setText("Informe o ID do usuário: ");

        botaoProcurarID.setText("Procurar");
        botaoProcurarID.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoProcurarIDActionPerformed(evt);
            }
        });

        labelNotFound.setText("Usuário não encontrado");

        labelRemovido.setText("Usuário removido com sucesso");

        labelNaoRemovido.setText("Não foi possível remover o usuário");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(labelMatricula, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(labelID)
                            .addComponent(labelNome, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(labelEmail))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(campoEmail)
                                .addComponent(campoNome)
                                .addComponent(campoMatricula, javax.swing.GroupLayout.PREFERRED_SIZE, 351, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(labelNotFound, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                    .addComponent(campoID, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGap(18, 18, 18)
                                    .addComponent(botaoProcurarID)))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(119, 119, 119)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(labelRemovido, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addComponent(botaoRemover)
                                .addGap(69, 69, 69)
                                .addComponent(botaoCancelar))
                            .addComponent(labelNaoRemovido, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addContainerGap(72, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(37, 37, 37)
                .addComponent(labelNotFound)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelID)
                    .addComponent(campoID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(botaoProcurarID))
                .addGap(79, 79, 79)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(campoMatricula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelMatricula))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(campoNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelNome))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(campoEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelEmail))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(botaoRemover)
                    .addComponent(botaoCancelar))
                .addGap(18, 18, 18)
                .addComponent(labelRemovido)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(labelNaoRemovido)
                .addGap(125, 125, 125))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void botaoRemoverActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoRemoverActionPerformed
}//GEN-LAST:event_botaoRemoverActionPerformed

    private void botaoCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoCancelarActionPerformed
        dispose();
}//GEN-LAST:event_botaoCancelarActionPerformed

    private void botaoProcurarIDActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoProcurarIDActionPerformed
        int idUsuario = Integer.parseInt(campoID.getText());
        if (procuraUsuario(idUsuario) != null) {
            Usuario usuario = procuraUsuario(idUsuario);
            campoMatricula.setText(usuario.getMatricula());
            campoNome.setText(usuario.getNome());
            campoEmail.setText(usuario.getEmail());
            labelNotFound.setVisible(false);
        } else {
            labelNotFound.setVisible(true);

        }

}//GEN-LAST:event_botaoProcurarIDActionPerformed

    private void botaoRemoverMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_botaoRemoverMouseClicked
        int idUsuario = Integer.parseInt(campoID.getText());
        if (procuraUsuario(idUsuario) != null) {
            if (Sistema.removerUsuario(loginProfessor, idUsuario)) {
                labelRemovido.setVisible(true);
                labelNaoRemovido.setVisible(false);
            } else {
                labelNaoRemovido.setVisible(true);
                labelRemovido.setVisible(false);
            }
        }
    }//GEN-LAST:event_botaoRemoverMouseClicked

    private Usuario procuraUsuario(int id) {
        return Sistema.getUsuario(id);
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new RemoveUsuario().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botaoCancelar;
    private javax.swing.JButton botaoProcurarID;
    private javax.swing.JButton botaoRemover;
    javax.swing.JTextField campoEmail;
    private javax.swing.JTextField campoID;
    javax.swing.JTextField campoMatricula;
    javax.swing.JTextField campoNome;
    private javax.swing.JLabel labelEmail;
    private javax.swing.JLabel labelID;
    private javax.swing.JLabel labelMatricula;
    private javax.swing.JLabel labelNaoRemovido;
    private javax.swing.JLabel labelNome;
    private javax.swing.JLabel labelNotFound;
    private javax.swing.JLabel labelRemovido;
    // End of variables declaration//GEN-END:variables
}
